package com.huluobo.a2204monthparkdemo.login

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.LoginBean
import com.huluobo.base.db.UserDao
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiServiceLogin
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/9/3.
 */
@HiltViewModel
class LoginViewModel @Inject constructor(
    val apiServiceLogin: ApiServiceLogin,
    val dao: UserDao
) : BaseViewModel() {
    val loginSuccess by lazy { MutableLiveData<String>() }

    fun login(body: RequestBody) {
        executeNetRequest(
            { apiServiceLogin.login(body) },
            loginSuccess::postValue
        )
    }

    val insertSuccess by lazy { MutableLiveData<String>() }
    fun insertUserInfo(userBean: LoginBean) {
        executeDb(
            {
                dao.insertUserInfo(userBean)
                "添加成功"
            },
            insertSuccess::postValue
        )
    }
}